import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.test.sdk.pay.util.ConnectionUtil;

/**
 * @author 徒有琴
 */
public class ExchangeSender {
    private final static String EXCHANGE_NAME = "test_exchange_direct";

    public static void main(String[] argv) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        System.out.println(connection);
        Channel channel = connection.createChannel();
        //DIRECT 完全匹配才能通信
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        String message = "Hello World1 key!";
        //将消息发送到交换机,如果此时没有队列绑定,则消息会丢失,因为交换机没有存储消息的能力
        //第二个参数是路由键
        channel.basicPublish(EXCHANGE_NAME, "key", null, message.getBytes());
        System.out.println(" 发送消息 '" + message + "'");
        channel.close();
        connection.close();
    }
}
